<?php

namespace app\admin\controller\meter;

use app\common\controller\Backend;

use think\Controller;
use think\Request;

/**
 * 仪表记录
 *
 * @icon fa fa-circle-o
 */
class Log extends Backend
{

    /**
     * MeterLog模型对象
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('MeterLog');

        //$this->view->assign('meter',model('Meter')->field('id,name')->select());
    }

    public function index()
    {

        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit, $orderParams) = $this->buildparams();
            $total = $this->model->where($where)->count();
            $list = $this->model->with('meter')->where($where)->order($orderParams)->limit($offset, $limit)->select();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }

    public function add()
    {
        return parent::create('form');
    }

    public function edit($ids = NULL)
    {
        return parent::modify($ids, 'form');
    }

    public function del($ids = null)
    {
        $where = array(
            'id' => array('in', $ids)
        );
        parent::delete($where);
    }

    public function import()
    {
        if ($this->request->isPost()) {
            //TODO 导入数据
            $this->success('导入成功');
        }
        return $this->fetch('import');
    }
}
